#include "PointLabTools/BoundingBox.h"

namespace PointlabTools
{
	void BoundingBox::compute(const PointLabCore::IPointCloud* cloud, PointLabCore::Vector3& minPt, PointLabCore::Vector3& maxPt)
	{
		int pointsNum = cloud->getPointNum();

		if (pointsNum == 0)
		{
			assert(false);
		}
		else
		{
			int index = 0;

			minPt = cloud->getPointCoord(index);
			maxPt = cloud->getPointCoord(index);

			index++;

			while (index < pointsNum)
			{
				PointLabCore::Vector3 point = cloud->getPointCoord(index);

				if (point.x < minPt.x)
				{
					minPt.x = point.x;
				}
				else if (point.x > maxPt.x)
				{
					maxPt.x = point.x;
				}

				if (point.y < minPt.y)
				{
					minPt.y = point.y;
				}
				else if (point.y > maxPt.y)
				{
					maxPt.y = point.y;
				}

				if (point.z < minPt.z)
				{
					minPt.z = point.z;
				}
				else if (point.z > maxPt.z)
				{
					maxPt.z = point.z;
				}

				index++;
			}
		}
	}

}
